var PublicPostHanlder=function () {
    var csrf_token=$("meta[name='csrf-token']").attr("content");
    var editor=editor=new window.wangEditor("#editor");
    editor.config.uploadImgServer="/upload/post/image/";
    editor.config.uploadFileName="image";
    editor.config.uploadImgHeaders={
        "X-CSRFToken":csrf_token
    }
    editor.config.uploadImgMaxSize=1024*1024*5;
    this.editor=editor;
    this.editor.create();
}

PublicPostHanlder.prototype.listenSubmitBtn=function () {
    var that=this;
    $("#submit-btn").on("click",function (event) {
        event.preventDefault();
        var title=$("input[name='title']").val();
        var board_id=$("select[name='board_id']").val();
        var content=that.editor.txt.html();
        zlajax.post({
            url:'/public/post/',
            data:{
                title,content,board_id
            },
            success:function (result) {
                if(result['code']==200){
                    let post_id=result['data']['post_id']
                    window.location='/post/detail/'+post_id;
                }else{
                    alert(result['message'])
                }

            }
        })
    })
}

PublicPostHanlder.prototype.run=function () {
    this.listenSubmitBtn();
}

$(function () {
    var handler=new PublicPostHanlder();
    handler.run();
})